package cn.edu.jxau.framework.dao.core;

import java.sql.Connection;
import java.sql.SQLException;



public abstract class BaseSqlClass {
	protected Connection conn;
	
	BaseSqlClass(){
		this.conn = jdbcUtils.getConnection();
	}
	
	public void releaseConnection(){
		try {
			//有些sql语句在close前会要求回滚，所以设置为自动提交
			conn.setAutoCommit(true);
			this.conn.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	public void setAutoCommit(boolean flag){
		try {
			conn.setAutoCommit(flag);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public boolean commmit(){
		//提交事务
		try {
			conn.commit();
		} catch (SQLException e) {
			rollback();
			e.printStackTrace();
		}
		return false;
		
	}
	protected boolean getAutoCommit(){
		try {
			return conn.getAutoCommit();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return false;
	}
	
	protected void rollback(){
		try {
			conn.rollback();
		
		} catch (SQLException e1) {
			e1.printStackTrace();
		}
	}
	
	
	protected Connection getConn(){
		return conn;
	}
}
